<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">

            <!-- 放置表单 -->
            <el-form label-width="120px" :model="userIfon" :rules="rules" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="userIfon.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="password">
                <el-input v-model="userIfon.password" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="saveUserDetailById">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <!-- 放置个人详情 -->
            <UserInfo />
          </el-tab-pane>
          <!-- <user-info /> -->

          <el-tab-pane label="岗位信息">
            <!-- 放置岗位信息 -->
            <JobInfro />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserDetailByIdAPI, saveUserDetailByIdAPI } from '@/api/employee'
import UserInfo from './components/UserInfo.vue'
import JobInfro from './components/JobInfro.vue'
export default {
  name: 'Detail',
  components: { UserInfo, JobInfro },
  props: {
    id: {
      type: [Number, String],
      required: true
    }
  },
  data() {
    return {
      userIfon: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
  },
  watch: {},
  created() {
    this.getUserDetailById()
  },
  methods: {
    async  getUserDetailById() {
      // console.log(this.$route) 这里也有id
      const { username } = await getUserDetailByIdAPI(this.id)
      this.userIfon.username = username
    },
    async saveUserDetailById() {
      try {
        await saveUserDetailByIdAPI({
          id: this.id,
          ...this.userIfon })
        this.$message.success('操作成功')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>
